package com.timebank.common.chaincode.entity;


import com.alibaba.fastjson2.JSON;
import lombok.*;
import lombok.experimental.Accessors;
import org.hyperledger.fabric.contract.annotation.DataType;
import org.hyperledger.fabric.contract.annotation.Property;

import java.io.Serializable;
import java.util.Objects;

/**
 * 智能合约 用户对象
 * @author shiliuyinzhen
 */
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Data
@DataType
@Accessors(chain = true)
public class User  implements Serializable {

    private static final long serialVersionUID = 1L;

    /** 用户Id */
    @Property
    private String userId;

    /** 用户名 */
    @Property
    private String userName;

    /** 时间币 */
    @Property
    private double timeCoin;

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if ((obj == null) || (getClass() != obj.getClass())) {
            return false;
        }
        User other = (User) obj;
        return Objects.deepEquals(
                new String[] {getUserId(), getUserName()},
                new String[] {other.getUserId(), other.getUserName()})
                &&
                Objects.deepEquals(
                        new double[] {getTimeCoin()},
                        new double[] {other.getTimeCoin()});
    }

    @Override
    public int hashCode() {
        return Objects.hash(getUserId(), getUserName(), getTimeCoin());
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
